# menustate.rb
# created by: Dan Alexander
# date: 3/6/2011
# license: New BSD License
#
# MenuState
# The menu state, inherited from gamestate.
# This handles all of the main menus.

require "rubygems"
require "rubygame"

include Rubygame

class MessageGameState < GameState

	def initialize(scr)
		super(scr) #GameState parent class initialize
		
		#set up the fonts
		TTF.setup
		@fontTitle = TTF.new "resources/font.ttf", 28
		@fontText = TTF.new "resources/font.ttf", 22
		
		#colors used for menu text
		@colorTitle = [255,255,0]
		@colorText = [128,128,128]
		
		@selected = 0
		
		@previousState
		
		@message_title = ""
		@message_text = ""
	end

	def show msg, title=nil
		@previousState = $currentstate
		
		@message_text = msg
		@message_title = title
		
		$currentstate = "message"
	end

	def update
		$event_queue.each do |event|
			case event
				when Events::KeyReleased
					if event.key == :return #do action on currently selected menu item
						$currentstate = @previousState						
					end				
				when Events::QuitRequested
					$should_run = false
			end
		end
  
	end
	
	def draw
		#fill the screen with a background color
		@screen.fill([0,0,0],[0,0,@screen.w(),@screen.h()])
		
		#message title
		if @message_title != nil
			text_surface = @fontTitle.render_utf8 @message_title, true, @colorTitle
			rt = text_surface.make_rect
			rt.topleft = [@screen.width / 2 - rt.width / 2, 8]
			text_surface.blit @screen, rt
		end
		
		#MESSAGE TEXT
		text_surface = @fontText.render_utf8 @message_text, true, @colorText
		rt = text_surface.make_rect
		rt.topleft = [@screen.width / 2 - rt.width / 2, 100]
		text_surface.blit @screen, rt
		
		#press any key
		text_surface = @fontText.render_utf8 "...press enter to continue...", true, @colorText
		rt = text_surface.make_rect
		rt.topleft = [@screen.width / 2 - rt.width / 2, 300]
		text_surface.blit @screen, rt
		
	end
	
end